Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make natural key of userprofile unique #2249

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

Kakadus
Copy link
Collaborator

@Kakadus Kakadus commented Jul 16, 2024

close #2247

size of test_data.json increases a bit because every relation to userprofile now takes two lines...
size of test_data.json decreases a bit because every relation to userprofile now takes two less lines...

@Kakadus Kakadus changed the title Fix user none email Change make natural key of userprofile unique Jul 16, 2024
@Kakadus Kakadus changed the title Change make natural key of userprofile unique Make natural key of userprofile unique Jul 16, 2024
@Kakadus Kakadus marked this pull request as draft July 17, 2024 09:35
Copy link
Member

@richardebeling richardebeling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code on its own is fine with me

evap/evaluation/models.py Show resolved Hide resolved
@Kakadus
Copy link
Collaborator Author

Kakadus commented Aug 26, 2024

next try: we use the pk as natural key for UserProfile. ModelBackend has to be disabled because it still passes the email (USERNAME_FIELD) to get_by_natural_key, which causes a value error.

evap/evaluation/models.py Outdated Show resolved Hide resolved
@Kakadus
Copy link
Collaborator Author

Kakadus commented Aug 26, 2024

whyever the ci now breaks...

@Kakadus
Copy link
Collaborator Author

Kakadus commented Sep 2, 2024

@Kakadus Kakadus force-pushed the fix-user-none-email branch 2 times, most recently from 5059628 to d59095b Compare September 9, 2024 17:25
@Kakadus
Copy link
Collaborator Author

Kakadus commented Sep 9, 2024

okay.. Current solution: Add an unique, non-editable UUIDField, and make it the natural key

@Kakadus Kakadus force-pushed the fix-user-none-email branch 2 times, most recently from 8f5310e to e7f37d0 Compare September 9, 2024 17:40
@richardebeling
Copy link
Member

richardebeling commented Sep 9, 2024

okay.. Current solution: Add an unique, non-editable UUIDField, and make it the natural key

I think this is worse than del AbstractBaseUser.natural_key. We're not a library but an "end user" of django, so I'd be very confident that we're the only ones using that class. Manipulating it in hacky ways to work around bugs seems fine to me.

The additional database fields adds data clutter and migration clutter and is harder to reverse once django fixes their stuff.

Edit: Following the discussion on the django forums, we probably just want to ditch AbstractBaseUser, inherit from its base class, and just copy over the parts that we need

@Kakadus Kakadus force-pushed the fix-user-none-email branch 3 times, most recently from dc706da to c72bcd3 Compare September 30, 2024 19:33
@Kakadus Kakadus marked this pull request as ready for review September 30, 2024 20:55
Comment on lines +1655 to +1657
# Stores the raw password if set_password() is called so that it can
# be passed to password_changed() after the model is saved.
_password = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this? I don't think we care about password_changed.

Comment on lines +1668 to +1671
"""
Always return False. This is a way of comparing User objects to
anonymous users.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think our code uses this -- why do we need it?

(I wouldn't copy the docstring from the django class)

Comment on lines +1700 to +1702
def set_unusable_password(self):
# Set a value that will never be a valid hash
self.password = make_password(None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just make this the default value (factory) for the field? There's only one usage which would go away.

Comment on lines +1662 to +1664
def get_username(self):
"""Return the username for this User."""
return getattr(self, self.USERNAME_FIELD)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Loading of backup fails due to nullable natural_key: the USERNAME_FIELD
2 participants